package com.qf.cloud2204.microa.controller;

import com.qf.cloud2204.common.entity.User;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("/findAll")
    List<User> findAll(){
        User luffy = new User(100, "luffy");
        User zoro = new User(200, "zoro");
        List<User> users = Arrays.asList(luffy, zoro);
        return users;
    }

    @PostMapping("/update")
    User updateUser(@RequestBody User user){

        System.out.println("==========="+user);
        user.setName("wusuopu");
        return user;
    }

    @DeleteMapping("/delete/{id}")
    User deleteUser(@PathVariable("id") Integer id){
        System.out.println("==========="+id);
        return new User(id,"shanji");
    }


    @GetMapping("/find")
    User findUserByName(@RequestParam("username") String username){
        System.out.println("=========="+username);
        return new User(300,username);

    }
}
